package com.example.function_interface.consumer;

import com.example.function_interface.User;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;

/**
 * 代表了一个接受两个输入参数的操作，并且不返回任何结果
 */
public class BiConsumerTest {

    @Test
    public void myTest() throws Exception{
        List<User> userList = new ArrayList<>();
        userList.add(new User(1, "张三", 12, false));
        userList.add(new User(2, "李四", 22, false));
        userList.add(new User(3, "王五", 32, true));
        userList.add(new User(4, "郑静", 2, true));

        BiConsumer<User, Integer> biConsumer = (user, age) -> {
            System.out.println(user.getName()+"的年龄是"+user.getAge());
        };
        BiConsumer<User, Integer> biConsumer2 = new BiConsumer() {
            @Override
            public void accept(Object o, Object o2) {
                User user = (User) o;
                Integer age = (Integer) o2;
                if (user.getAge() >= age) {
                    System.out.println(user.getName() + " 大于等于指定年龄" + age);
                } else {
                    System.out.println(user.getName() + " 小于指定年龄" + age);
                }

            }
        };
        BiConsumer<User, Integer> comboBiConsumer = biConsumer.andThen(biConsumer2);
        for (User user : userList) {
            comboBiConsumer.accept(user, 18);
        }

    }
}
